#“http://data.sports.sohu.com/nba/nb
#a_players_rank.php?order_by=points&spm=smpc.fb-nba-home.top-dc.2.1620824904040nf6byr7”，
#爬取前50名球员所有的数据打包成JSON数据或CSV数据写入到文件中。

import requests
from bs4 import BeautifulSoup

url="http://data.sports.sohu.com/nba/nba_players_rank.php?order_by=points&spm=smpc.fb-nba-home.top-dc.2.1620824904040nf6byr7";
headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
    };
resp=requests.get(url=url;headers=headers);
resp.encoding="utf-8";
bf=BeautifulSoup(resp.text,"lxml");
allList=[];
groupList=bf.select('.table01>tr');
for i in groupList:
    for j in i:
       array1=[];
       array1.append(j);
    allList.append(array1);

file=open("group.txt","w");
file.write(allList);
